package com.zyd.shiro.business.controller.pak;

import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.entity.Inventory;
import com.zyd.shiro.business.service.PakAssetsService;
import com.zyd.shiro.business.service.PakInventoryService;
import com.zyd.shiro.framework.object.BaseConditionVO;
import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import java.util.List;


@RestController
@RequestMapping("/inventory")
@Api(description = "资产盘点")
public class PakInventoryController {
    @Autowired
    private PakInventoryService inventoryService;

    @Autowired
    private PakAssetsService assetsService;

    @PostMapping
    @ApiOperation(value="添加", produces="application/json")
    public ResponseVO insert(Inventory inventory) {
        inventoryService.insert(inventory);
        boolean reuslt = assetsService.inventory(inventory.getPakInventory());
        if(reuslt){
            return ResultUtil.success("添加成功！",inventory);
        }else {
            return ResultUtil.error("添加失败！");
        }
    }
    @GetMapping(value = "/select")
    @ApiOperation(value="查询", produces="application/json")
    public ResponseVO select(Inventory inventory) {
        int num = assetsService.inventoryNum(inventory.getPakInventory());
        return ResultUtil.success("查询成功！",num);
    }

    @PutMapping
    @ApiOperation(value="修改", produces="application/json")
    public ResponseVO update(Inventory inventory) {
        inventoryService.updateSelective(inventory);
        return ResultUtil.success("修改成功！",inventory);
    }

    @DeleteMapping(value = "/{id}")
    @ApiOperation(value="主键删除", produces="application/json")
    public ResponseVO delete(@PathVariable(name="id") Long id){
        inventoryService.removeByPrimaryKey(id);
        return ResultUtil.success("删除成功！",null);
    }

    @GetMapping
    @ApiOperation(value="分页查询", produces="application/json")
    public PageResult page(BaseConditionVO vo) {
        PageInfo<Inventory> pageInfo = inventoryService.findPageBreakByCondition(vo);
        return ResultUtil.tablePage(pageInfo);
    }

    @GetMapping(value = "/all")
    @ApiOperation(value="查询所有", produces="application/json")
    public ResponseVO list() {
        List<Inventory> inventorys = inventoryService.listAll();
        return ResultUtil.success("查询成功！",inventorys);
    }



}